let CollisionModule =require("CollisionModule");
let ExplodeProp =require("ExplodeProp");
let BooseProp =require("BoosProp");

//cc.error("随机"+cc.random0To1());
cc.Class({
    extends: cc.Component,

    properties: {
        isProp:false,//是否是直接触发道具
        PropType:"",

        isOver:false,//子物体已经清空

        dropSpeed:100,

    },


    start () {

    },

    StartRandomPickValue(value){
        for(let chi of this.node.children){
            let cm= chi.getComponent(CollisionModule);
            cm.needDesCount =parseInt(cc.random0To1()*2)*value+1;
        }

    },


    UpdateFun()
    {
        if(this.node.children.length===0){
            this.isOver =true;
            return;
        }

        this.node.y-=this.dropSpeed;

        ///！！父物体下落  并 不会带会带着子物体
        if(this.isProp)
        {
            switch(this.PropType){
                case "ExplodeProp":
                    let exp = this.node.getComponentInChildren(ExplodeProp);
                    exp.UpdateFun();
                    break;
                case　"BossBall":
                    let value =this.node.getComponentInChildren(BooseProp);
                    value.UpdateFun();
                    break;
            }
            return;
        }

        // if(this.isProp)
        // {
        //     switch(this.PropType){
        //         case "ExplodeProp":
        //             let exp = this.node.getComponentInChildren(ExplodeProp);
        //             exp.UpdateFun();
        //             break;
        //         case "ScoreDobuleProp":
        //             let dou =this.node.getComponentInChildren(ScoreDouble);
        //             dou.UpdateFun();
        //             break;
        //         case "AddBarSpeedProp":
        //             let asp =this.node.getComponentInChildren(AddBarSpeedProp);
        //             asp.UpdateFun();
        //             break;
        //         case "AddBarLengthProp":
        //             let abl =this.node.getComponentInChildren(AddBarLengthProp);
        //             abl.UpdateFun();
        //             break;
        //         case "AddBallBigerProp":
        //             let abb =this.node.getComponentInChildren(AddBallBigerProp);
        //             abb.UpdateFun();
        //             break;
        //         case "DoubleBallProp":
        //             let dbp =this.node.getComponentInChildren(DoubleBallProp);
        //             dbp.UpdateFun();
        //             break;
        //     }
        //     return;
        // }





        for(let chi of this.node.children){
            let cm= chi.getComponent(CollisionModule);
            if(cm!==null){
                cm.UpdateFun();
            }

        }
    },

    Explode(targetpos,length2)//为平方长度
    {
        if(this.isProp){
            return;
        }

        for(let chi of this.node.children){
            let cm= chi.getComponent(CollisionModule);
            if(cm!==null){
                cm.Explode(targetpos,length2);
            }

        }

    }

    // update (dt) {},
});
